layui.define(['element', 'utils', 'bodyTab', 'conf', 'NProgress'], function (exports) {
    var utils = layui.utils,
        element = layui.element,
        config = layui.conf,
        NProgress = layui.NProgress,
        bodyTab = layui.bodyTab;


    /**
     * @author: ares
     * @date: 2020/12/23 11:08
     * @description: 切换页面
     * @param{object} data
     */
    function changePage(data) {
        bodyTab.addTab(data.title, location.hash.substr(1), data.filePath, data.icon, data.refresh == undefined ? 'init' : data.refresh, function () {
            utils.highLightAside();
            utils.updateBreadcrumb(router);
            element.render();
        });
    }

    var routes = {
            '/homepage': function () {
                router.meta = {
                    breadcrumb: [
                        {
                            path: config.homePagePath,
                            title: config.homePageTitle,
                            filePath: config.homePageFilePath,
                            icon: config.homePageIcon,
                        }
                    ]
                };
                router.params = {};
            },
            '/consultation': {
                '/list': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/consultation/list',
                                title: '会诊病例',
                                filePath: 'pages/consultation/list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {

                    };
                },
            },
            '/referral': {
                '/list': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/referral/list',
                                title: '转诊病例',
                                filePath: 'pages/referral/transfer.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/fast': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/referral/list',
                                title: '转诊病例',
                                filePath: 'pages/referral/transfer.html',
                                icon: '',
                            },
                            {
                                path: '/referral/fast',
                                title: '快速转诊',
                                filePath: 'pages/referral/add_referral.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/new/:transferId': function (transferId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/referral',
                                title: '转诊病例',
                                filePath: 'pages/referral/transfer.html',
                                icon: '',
                            },
                            {
                                path: '/referral/new/' + transferId,
                                title: '新建转诊门诊',
                                filePath: 'pages/patient/new_transfer_medical_record.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        transferId: transferId
                    };
                },
                '/history/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/referral',
                                title: '转诊病例',
                                filePath: 'pages/referral/transfer.html',
                                icon: '',
                            },
                            {
                                path: '/referral/history/' + emrId,
                                title: '转诊历史',
                                filePath: 'pages/referral/transfer_history.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
            },
            '/evaluation': {
                '/list': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/evaluation/list',
                                title: '整体评估',
                                filePath: 'pages/prcp/evaluation_prcp_list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/create/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/evaluation/list',
                                title: '整体评估',
                                filePath: 'pages/prcp/evaluation_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/evaluation/create/' + emrId,
                                title: '新建整体评估',
                                filePath: 'pages/prcp/add_evaluation_prcp.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/createold/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/evaluation/list',
                                title: '整体评估',
                                filePath: 'pages/prcp/evaluation_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/evaluation/create/' + emrId,
                                title: '新建整体评估-老的',
                                filePath: 'pages/prcp/add_evaluation_prcp_old.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/detail/:emrId/:prcpId': function (emrId, prcpId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/evaluation/list',
                                title: '整体评估',
                                filePath: 'pages/prcp/evaluation_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/evaluation/detail/' + emrId + '/' + prcpId,
                                title: '评估详情',
                                filePath: 'pages/prcp/evaluation_prcp_detail.html',
                                refresh: 'refresh',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId,
                        prcpId: prcpId,
                    };
                },
                '/gauge': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/evaluation/list',
                                title: '整体评估',
                                filePath: 'pages/prcp/evaluation_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/evaluation/gauge',
                                title: '评估',
                                filePath: 'pages/gauge/gauge_tab.html',
                                icon: '',
                                refresh: 'refresh',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
            },
            '/training': {
                '/list': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/list',
                                title: '训练处方',
                                filePath: 'pages/prcp/training_prcp_list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/plan/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/plan/' + emrId,
                                title: '康复训练方案',
                                filePath: 'pages/trainingplan/training_plan.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/record/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/record/' + emrId,
                                title: '康复训练记录',
                                filePath: 'pages/trainingplan/training_record.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/create/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/list',
                                title: '训练处方',
                                filePath: 'pages/prcp/training_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/training/create/' + emrId,
                                title: '新建训练处方',
                                filePath: 'pages/prcp/add_training_prcp.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/createold/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/list',
                                title: '训练处方',
                                filePath: 'pages/prcp/training_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/training/create/' + emrId,
                                title: '新建训练处方-老的',
                                filePath: 'pages/prcp/add_training_prcp_old.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/detail/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/training/list',
                                title: '训练处方',
                                filePath: 'pages/prcp/training_prcp_list.html',
                                icon: '',
                            },
                            {
                                path: '/training/detail/' + emrId,
                                title: '训练处方详情',
                                filePath: 'pages/prcp/training_prcp_detail.html',
                                refresh: 'refresh',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
            },
            '/schedule': {
                'mgr': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/schedule/mgr',
                                title: '治疗师排班',
                                filePath: 'pages/scheduling/D_therapist_scheduling.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                'referralStat': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/schedule/mgr',
                                title: '治疗师排班',
                                filePath: 'pages/scheduling/D_therapist_scheduling.html',
                                icon: '',
                            },
                            {
                                path: '/schedule/referralStat',
                                title: '转诊统计',
                                filePath: 'pages/scheduling/referral_stat_show.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                'table': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/schedule/mgr',
                                title: '治疗师排班',
                                filePath: 'pages/scheduling/D_therapist_scheduling.html',
                                icon: '',
                            },
                            {
                                path: '/schedule/table',
                                title: '排班一览表',
                                filePath: 'pages/scheduling/D_therapist_schedule.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                }
            },
            '/setting': {
                '/ctrl': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/ctrl',
                                title: '质控统计',
                                filePath: 'pages/system/ctrl/index.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/person': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/person',
                                title: '人员管理',
                                filePath: 'pages/system/person_ctrl.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/internship': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/internship',
                                title: '实习老师管理',
                                filePath: 'pages/system/internship_ctrl.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/project': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/project',
                                title: '项目管理',
                                filePath: 'pages/system/project_ctrl.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/combo': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/setting',
                                title: '系统管理',
                            },
                            {
                                path: '/setting/combo',
                                title: '套餐管理',
                                filePath: 'pages/system/combo/list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
            },
            '/message': {
                '/self': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/message',
                                title: '消息管理',
                            },
                            {
                                path: '/message/self',
                                title: '我的消息',
                                filePath: 'pages/message/list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/overTask': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/message',
                                title: '消息管理',
                            },
                            {
                                path: '/message/overTask',
                                title: '历史任务',
                                filePath: 'pages/message/my_over_task_list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
                '/task': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '/message',
                                title: '消息管理',
                            },
                            {
                                path: '/message/task',
                                title: '待办任务',
                                filePath: 'pages/message/my_task_list.html',
                                icon: '',
                                isLeaf: true
                            }
                        ]
                    };
                    router.params = {};
                },
            },
            '/emr': {
                '/create': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '病例',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/emr/create',
                                title: '新建病例',
                                filePath: 'pages/emr/add.html',
                                icon: ''
                            }
                        ]
                    };
                    router.params = {};
                },
                '/info/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '病例',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/emr/info/' + emrId,
                                title: '查看病例',
                                filePath: 'pages/emr/info.html',
                                icon: '',
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
                '/clinicDetail/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '病例',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/emr/clinicDetail/' + emrId,
                                title: '病例详情',
                                filePath: 'pages/clinic/disease_detail_info.html',
                                refresh: 'refresh',
                                icon: '',
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId
                    };
                },
            },
            '/user': {
                '/info': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '用户管理',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/user/info',
                                title: '个人资料',
                                filePath: 'pages/user/userinfo.html',
                                icon: ''
                            }
                        ]
                    };
                    router.params = {};
                },
                '/modifyPwd': function () {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '用户管理',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/user/modifyPwd',
                                title: '修改密码',
                                filePath: 'pages/user/changePwd.html',
                                icon: ''
                            }
                        ]
                    };
                    router.params = {};
                },
            },
            '/report': {
                '/create/:emrId': function (emrId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '检查报告',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/report/create/' + emrId,
                                title: '上传报告',
                                filePath: 'pages/report/upload_report.html',
                                icon: '',
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId,
                    };
                },
                '/detail/:emrId/:reportId': function (emrId, reportId) {
                    router.meta = {
                        breadcrumb: [
                            {
                                path: '',
                                title: '检查报告',
                                filePath: '',
                                icon: ''
                            },
                            {
                                path: '/report/detail/' + emrId + '/' + reportId,
                                title: '报告详情',
                                filePath: 'pages/report/upload_report_detail.html',
                                refresh: 'refresh',
                                icon: '',
                            }
                        ]
                    };
                    router.params = {
                        emrId: emrId,
                        reportId: reportId,
                    };
                },
            },
        },
        router = Router(routes).configure({
            on: function () {
                router.meta && changePage(router.meta.breadcrumb.slice(-1)[0]);
            },
            before: function () {
                NProgress.done();
            },
            after: function () {
                NProgress.start();
                NProgress.inc();
            },
            notfound: function () {
                console.log('>>>路由匹配失败<<<')
            }
        });
    router.init();
    exports('routers', router)
})